using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D.IK;

public class PlayerBody : MonoBehaviour
{
	public Player player;

	public float armor;

	public float strength;

	public float speed;

	public int kick;

	public float vomitResistance;

	[Range(0f, 1f)]
	public float backlashChance;

	public float backlashDamage;

	public GameObject gunPivot;

	public GameObject meleeWeaponPivot;

	public GameObject leftHandIK;

	public GameObject rightHandIK;

	public GameObject leftHandJoint;

	public GameObject rightHandJoint;

	public GameObject leftArm;

	public GameObject rightArm;

	public GameObject leftForearm;

	public GameObject rightForearm;

	public GameObject leftHand;

	public GameObject rightHand;

	public GameObject magazineHolder;

	public GameObject primaryWeaponHolder;

	public GameObject secondaryWeaponHolder;

	public GameObject meleeWeaponHolder;

	public Animator animator;

	public Collider2D kickCollider;

	public AudioClip[] footStepAudios;

	public IKManager2D ikManager;

	public float baseArmor;

	public List<Collider2D> colliders = new List<Collider2D>();

	public Rigidbody2D[] rbs;

	private Weapon _weapon;

	private void Awake()
	{
		Collider2D[] componentsInChildren = GetComponentsInChildren<Collider2D>();
		player = base.transform.parent.parent.GetComponent<Player>();
		Collider2D[] array = componentsInChildren;
		foreach (Collider2D collider2D in array)
		{
			if (!(collider2D.tag != "Body"))
			{
				colliders.Add(collider2D);
			}
		}
		rbs = GetComponentsInChildren<Rigidbody2D>();
		baseArmor = armor;
	}

	public void ThownObject()
	{
		ThownObject thownObject = Object.Instantiate(player.placingTool.thrownObject, leftHandJoint.transform.position, Quaternion.identity);
		thownObject.gameObject.SetActive(value: true);
		thownObject.gameObject.layer = player.groundLayer;
		thownObject.rigidBody.AddForce(player.placingTool.thrownObject.thownForce * Vector2.right);
		thownObject.rigidBody.AddTorque(-0.055f);
		player.campaignGame.CancelPlaceTools();
	}

	public void StartPlaceItem()
	{
		_weapon = player.weapon;
		player.PutBackWeapon();
	}

	public void EndPlaceItem()
	{
		player.isPlacingItem = false;
		player.releaseLeftHand = false;
		player.releaseRightHand = false;
		if ((bool)player.placingTool)
		{
			player.placingTool.Placed();
			player.placingTool = null;
		}
		if (_weapon == player.primaryWeapon)
		{
			player.EquipPrimaryWeapon();
			player.weapon.animator.enabled = true;
		}
		else if (_weapon == player.secondaryWeapon)
		{
			player.EquipSecondaryWeapon();
			player.weapon.animator.enabled = true;
		}
		else if ((bool)player.meleeWeapon)
		{
			player.EquipMeleeWeapon();
			player.meleeWeapon.animator.enabled = true;
		}
	}

	public void PlayRandomFootStepAudio()
	{
		player.audioSource.PlayOneShot(footStepAudios[Random.Range(0, footStepAudios.Length)]);
	}

	public void PlayAudio(AudioClip audio)
	{
		player.audioSource.PlayOneShot(audio);
	}

	public void RestArm()
	{
		leftArm.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, -90f));
		rightArm.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, -90f));
		rightArm.transform.Find("ForeArmRb").rotation = Quaternion.Euler(new Vector3(0f, 0f, 90f));
	}

	private void LateUpdate()
	{
		leftArm.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, leftArm.transform.rotation.eulerAngles.z));
		rightArm.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, rightArm.transform.rotation.eulerAngles.z));
		leftForearm.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, leftForearm.transform.rotation.eulerAngles.z));
		rightForearm.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, rightForearm.transform.rotation.eulerAngles.z));
	}
}
